PRG 1.0 TXT

/*
	Fractal
*/

//-----------------------------------------------------------------------------
// [CONFIG]

include "..\program_include.ocf"

object Program
{
	type		= e_program.DIFFUSE;
	layer_bits	= e_render_layer_bits.ALL;
	
	uniforms	= array /*string*/ {
		"transform", "unTransform.",
		"timer", 	 "unTime",
		"viewport",	 "unViewport"
	}
}


//-----------------------------------------------------------------------------
// [VERTEX]

#version 330 core
#pragma optimize(on)

#define ATTR_POSITION	0

layout(location = ATTR_POSITION)	in vec3 inPosition;


uniform struct Transform {
	mat4	Projection;
} unTransform;


void main()
{
	gl_Position = unTransform.Projection * vec4(inPosition, 1.0);
}


//-----------------------------------------------------------------------------
// [FRAGMENT]

#version 330 core
#pragma optimize(on)

layout(location = 0, index = 0) out vec4	outColor;

uniform float	unTime;
uniform vec2	unViewport;

const int		colors = 8;
const vec3		vColors[colors] = vec3[] (
					vec3( 0.8, 0.9, 1.0 ),
					vec3( 0.5, 1.0, 0.8 ),
					vec3( 0.0, 0.7, 0.3 ),
					vec3( 0.0, 0.5, 0.1 ),
					vec3( 0.0, 0.3, 0.6 ),
					vec3( 0.0, 0.2, 0.6 ),
					vec3( 0.0, 0.1, 0.3 ),
					vec3( 0.0, 0.0, 0.2 )
				);/*
const vec3		vColors[colors] = vec3[] (
					vec3( 1.0, 1.0, 0.9 ),
					vec3( 1.0, 0.9, 0.6 ),
					vec3( 1.0, 0.7, 0.3 ),
					vec3( 0.9, 0.4, 0.0 ),
					vec3( 0.8, 0.3, 0.0 ),
					vec3( 0.6, 0.1, 0.0 ),
					vec3( 0.4, 0.0, 0.2 ),
					vec3( 0.0, 0.0, 0.5 )
				);*/

vec3 GetColor(float f)
{
	float	a = f * colors;
	int		i = int( clamp( a, 0.0, float(colors-2) ) );
	
	a -= float(i);
	
	return mix( vColors[i], vColors[i+1], a );
}


vec4 GenFractalColor()
{
	vec2	p	 = -1.0 + 2.0 * gl_FragCoord.xy / unViewport;
	vec2	cc	 = vec2( cos(0.25*unTime), sin(0.25*unTime*1.423) );
	
	float	dmin = 1000.0;
	vec2	z	 = p * vec2( unViewport.x/unViewport.y, 1.0 );
	
	for (int i = 0; i < 32; ++i)
	{
		z = cc + vec2( z.x*z.x - z.y*z.y, 2.0*z.x*z.y );
		float	m2 = dot( z, z );
		
		if ( m2 > 100.0 )
			break;
			
		dmin = min( dmin, m2 );
	}
	
	return vec4( GetColor( sqrt( sqrt( dmin ) ) * 0.7 ), 1.0 );
}


void main()
{
	outColor = GenFractalColor();
}

// [END]
